package br.net.atasacramental.menu.dao;
import br.net.atasacramental.menu.model.ItemMenu;
import br.net.atasacramental.util.ConexaoDB;

import java.util.List;
import java.util.HashMap;
import java.util.Map;
/**
* @author alexandre.araujo
*/
public class ItemMenuDAO{
	private String[][] ordemP = {{"idItemMenu", "desc"}};
	@SuppressWarnings("unchecked")
    public List<ItemMenu> get() {
        return (List<ItemMenu>) ConexaoDB.get(ItemMenu.class,true,1,100,null,ordemP);
    }
    public ItemMenu getByIdItemMenu(int idItemMenu) {
        return (ItemMenu) ConexaoDB.getById(ItemMenu.class, idItemMenu);
    }
    @SuppressWarnings("unchecked")
    public List<ItemMenu> getByLabel(String label) {
     	Map<String,Object> params = new HashMap<String, Object>();
     	params.put("label", label);
        return (List<ItemMenu>) ConexaoDB.get(ItemMenu.class,true,1,100,params,ordemP);
    }
    @SuppressWarnings("unchecked")
    public List<ItemMenu> getByFuncao(String funcao) {
     	Map<String,Object> params = new HashMap<String, Object>();
     	params.put("funcao", funcao);
        return (List<ItemMenu>) ConexaoDB.get(ItemMenu.class,true,1,100,params,ordemP);
    }
    @SuppressWarnings("unchecked")
    public List<ItemMenu> getByIdMenu(int idMenu) {
     	Map<String,Object> params = new HashMap<String, Object>();
     	params.put("idMenu", idMenu);
        return (List<ItemMenu>) ConexaoDB.get(ItemMenu.class,true,1,100,params,ordemP);
    }    
    @SuppressWarnings("unchecked")
    public List<ItemMenu> getItensByIdGrupoIdMenu(int idGrupo,int idMenu){
        return (List<ItemMenu>) ConexaoDB.listar("from ItemMenu mi where exists  (from GrupoItem gi where gi.idGrupo = "+idGrupo+" and gi.idItemMenu = mi.idItemMenu ) and mi.idMenu = "+idMenu+" order by mi.idItemMenu desc");
    } 
    @SuppressWarnings("unchecked")
    public List<ItemMenu> getByIcone(String icone) {
        return (List<ItemMenu>) ConexaoDB.listar("from ItemMenu mi where mi.icone = '"+icone+"'" );
    }
    public boolean insert(ItemMenu mi){
        return ConexaoDB.insert(mi);
    }
    public boolean update(ItemMenu mi){
        return ConexaoDB.update(mi);
    }
    public boolean delete(ItemMenu mi){
        return ConexaoDB.delete(mi);
    }
}
